package com.lwj.test.uuid;

import java.util.Date;

public class UUID
{
  private long time;
  private static Object mutex = new Object();
  private static long lastTime = System.currentTimeMillis();
  private static long DELAY = 1L;

  private UUID() {
    synchronized (mutex) {
      boolean flag = false;
      while (!(flag)) {
        this.time = System.currentTimeMillis();
        if (this.time < lastTime + DELAY) {
          try {
            Thread.currentThread();
            Thread.sleep(DELAY);
          } catch (InterruptedException localInterruptedException) {
          }
        } else {
        	lastTime = this.time;
          flag = true;
        }
      }
    }
  }

  public static String getUUID() {
    String uuid = new UUID().toString();
    return uuid;
  }

  public String toString() {
    return "A" + Long.toString(this.time, 16); }

  public static void main(String[] args) {
	long startDate = System.currentTimeMillis();
    for (int i = 0; i < 10000; ++i) {
      System.out.println(getUUID());
      //System.out.println(getUUID());
    }
    long endDate = System.currentTimeMillis();
    System.out.println("----"+(endDate-startDate)/1000);
  }
}